/* 


*/
import { SIGN_SECRET as secretKey } from '@/config'
import md5 from 'md5'

function addSignToHeader(config) {
  const timestamp = new Date().getTime()

  let params = []

  params = ['timestamp=' + timestamp,  ...new Set(params)]
  params = params.sort((a, b) => (a + '').localeCompare(b + ''))
  params = params.join('').replace(/=/g, '') + secretKey

  let sign = md5(params).toUpperCase()

  config.headers = {
    ...config.headers,
    'X-Sign-Timestamp': timestamp,
    'X-Sign': sign
  }

  return config
}


export default addSignToHeader